using System;
using System.Collections.Generic;

namespace OpenWaves
{
    public abstract class UrlBuilder
    {
        private string fragment = String.Empty;
        private UrlPath path = UrlPath.Empty;
        private readonly IDictionary<string, object> query = new Dictionary<string, object>();

        public UrlPath Path
        {
            get { return this.path; }
            set
            { this.path = value ?? UrlPath.Empty; }
        }

        public string Fragment
        {
            get { return this.fragment; }
            set { this.fragment = value ?? String.Empty; }
        }

        public IDictionary<string, object> Query
        {
            get { return query; }
        }

        public Url ToUrl()
        {
            return this.BuildUrl();
        }

        public override string ToString()
        {
            return this.ToUrl().ToString();
        }

        protected abstract Url BuildUrl();

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Unescaped")]
        public string ToUnescapedString()
        {
            return this.ToUrl().ToUnescapedString();
        }
    }
}
